home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4526 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: news.MWCI.NET!usenet
  2. From: stuffle@pcii.net
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Overload >> vs. Write Met
  5. Date: 30 Jan 1996 19:48:46 GMT
  6. Organization: MidWest Communications, Inc.
  7. Message-ID: <4elsmu$n80@hihat.mwci.net>
  8. References: <60125190005$71C7@lasernet.com> <4els7t$n54@hihat.mwci.net>
  9. Reply-To: stuffle@pcii.net
  10. NNTP-Posting-Host: lan-pm1-30.pcii.net
  11. X-Newsreader: IBM NewsReader/2 v1.2.5
  12.  
  13. In <4els7t$n54@hihat.mwci.net>, stuffle@pcii.net writes:
  14. >In <60125190005$71C7@lasernet.com>, GEORGE BOUTWELL <george_boutwell@lasernet.com> writes:
  15. >>Ok...
  16. >>
  17. >>  Which is 'better' OOP 'Style', and/or 'Correctness' for
  18. >>Writing/Reading an Object's Data to/from Disk/Screen/Etc:
  19. >>
  20. >>Overloading the << and >>
  21. >>-or-
  22. >>writing a read method and a write method?
  23. >>
  24. >>Regards,
  25. >>
  26. >>George
  27. >>
  28. >> * OLX 1.53 * >ov++h+n AC*hanks for hanging up, dear.
  29. >
  30. >I would say "make it streamable!!"  If for any other reason, simply because 
  31. >it is a nice, object independent mechanism for writting to a stream.  Plus, the
  32. >syntax is much cleaner.
  33. >
  34. >ex:
  35. >ostream    os;
  36. >int        i;
  37. >TObj1        to1;    // TObj1 & TObj2 NOT related.
  38. >TObj2        to2;
  39.  
  40. alright, lets try the end of this again (since my news reader cut it off last time).
  41.  
  42. ostream    os;
  43. int        i;
  44. TObj1        to1;    // TObj1 & TObj2 NOT related.
  45. TObj2        to2;
  46.  
  47. //  other code here.
  48.  
  49. os << i << to1 << to2;    //  Nice and easy to read.  
  50.             //  consistent interface for all objects writting
  51.             //  to the out stream.
  52.  
  53. os << i;            //  Inconsistent interface between objects
  54. to1.write(os);        //  writting to the out stream.  Not as obvious
  55. to2.write(os);        //  what is happening.  Not as pretty.
  56.  
  57. Just my personal opinion.  Others (of course) may varry.
  58.  
  59.                                 \\\|///
  60.                                 | ~ ~ |
  61.                                (- @ @ -)
  62. //------------------------oOOo----(_)----oOOo------------------------
  63. //  Ken Sodemann  (Stuffle)             |   Get Warped!!!
  64. //  Stuffle@PCII.NET                    |   
  65. //  http://users.mwci.net/~stuffle/     |   
  66. //-------------------------------------------------------------------
  67.  
  68.